This Notebook explores photon data sets and the basic response of the photoreceptor model.
OPERATION:
TROUBLESHOOTING:
In [3]:
###Load the PyPlot package
import PyPlot
using GeneralizedMetropolisHastings
using GMHPhotoReceptor
println("Required packages loaded successfully")
In [4]:
###Load and display the photon sequence
photonfilename = "../data/naturallight.jld"
photons1 = photonsequence(photonfilename)
current1 = lightinducedcurrent(photonfilename)
###Plot the photon sequence and measured current
PyPlot.figure("Photon and Measurement Data")
PyPlot.clf()
PyPlot.subplot(211)
PyPlot.plot(dataindex(photons1),datavalues(photons1))
PyPlot.xlabel("Time (s)")
PyPlot.ylabel("Photons")
PyPlot.xlim(dataindex(photons1)[1],dataindex(photons1)[end])
PyPlot.grid("on")
PyPlot.subplot(212)
PyPlot.plot(dataindex(current1),datavalues(current1))
PyPlot.xlabel("Time (s)")
PyPlot.ylabel("Current (nA)")
PyPlot.xlim(dataindex(current1)[1],dataindex(current1)[end])
PyPlot.grid("on")
In [9]:
###Settings for the model
numvilli1 = 30000
#specify the values that determine the priors on the parameters
latencylocation = (2.0,3.5) #uniform distribution with (low,high) values
latencyscale = (0.2,0.7) #uniform distribution with (low,high) values
refractorylocation = (4.0,6.0) #uniform distribution with (low,high) values
refractoryscale = (1.5,2.5) #uniform distribution with (low,high) values
bumpamplitude = (3.0,5.0) #uniform distribution with (low,high) values
bumpshape = (log(3.0),0.3) #lognormal distribution with (location,scale) values
bumpscale = (log(2.5),0.3) #lognormal distribution with (location,scale) values
#4-parameter model with stochastic latency and refractory parameters and fixed bump parameters
mpolicy4 = policy(:photoreceptor;bump=:fixed)
params4 = parameters(:photoreceptor,mpolicy4,
latencylocation,latencyscale,refractorylocation,refractoryscale)
#7-parameter model with latency, refractory and bump parameters
mpolicy7 = policy(:photoreceptor;bump=:sample)
params7 = parameters(:photoreceptor,mpolicy7,
latencylocation,latencyscale,refractorylocation,refractoryscale,
bumpamplitude,bumpshape,bumpscale)
variance1 = [3600.0]
println("=====================================")
println("Model parameters defined successfully")
println("=====================================")
In [6]:
###Plot the distributions of model parameters
In [10]:
###Plot some examples of quantum bumps for random values drawn from the priors
#PyPlot.figure("Four-Parameter Model Bumps")
priorinit = trait(:initialize,:prior)
for i=1:4
PyPlot.figure()
v = GeneralizedMetropolisHastings.initvalues(priorinit,params4,Float64)
PyPlot.subplot(231)
end
#PyPlot.figure("Seven-Parameter Model Bumps")
for i=1:4
#subplot(220+i)
v = GeneralizedMetropolisHastings.initvalues(priorinit,params7,Float64)
println(v)
end
In [11]:
###Create a PhotoReceptor model
model4 = model(:photoreceptor,params4,photons1,current1,variance1,numvilli1,mpolicy4)
model7 = model(:photoreceptor,params7,photons1,current1,variance1,numvilli1,mpolicy7)
###Show the model
println("===========================")
println("Models defined successfully")
println("===========================")
show(model4)
show(model7)
In [17]:
###Evaluate the model for a set of random parameter values and plot the fit
###You can execute this cell as many times as you like
###Parameter values are drawn from the prior distributions on the parameters
numevaluations = 100
paramvals = GeneralizedMetropolisHastings.initvalues!(trait(:initialize,:prior),params4,zeros(Float64,length(params4)))
println("Evaluating the model $numevaluations times")
evaldata = evaluate!(model4,paramvals,numevaluations)
logposteriorvals = zeros(numevaluations)
for i=1:numevaluations
logposteriorvals[i] = loglikelihood(model4,evaldata[:,i])+logprior(params4,paramvals,Float64)
end
meanevaldata = mean(evaldata,2)
stdevaldata = std(evaldata,2)
PyPlot.figure("PhotoReceptor Model Evaluations")
PyPlot.subplot(211)
PyPlot.plot(dataindex(model4),evaldata)
PyPlot.plot(dataindex(model4),meanevaldata;label="mean",linewidth=1,color="white")
PyPlot.xlim(dataindex(model4)[1],dataindex(model4)[end])
PyPlot.legend(loc="upper right",fancybox="true")
PyPlot.ylabel("Current (nA)")
PyPlot.title("Variability in Light-Induced Current for 100 Model Evaluations")
PyPlot.subplot(212)
PyPlot.plot(dataindex(model4),stdevaldata)
PyPlot.plot(dataindex(model4),mean(stdevaldata,2),linewidth=1)
PyPlot.xlim(dataindex(model4)[1],dataindex(model4)[end])
PyPlot.xlabel("Time (s)")
PyPlot.ylabel("STD of Current (nA)")
PyPlot.grid("on")
PyPlot.figure("PhotoReceptor Measured vs Model Fit")
PyPlot.subplot(211)
PyPlot.plot(dataindex(model4),measurements(model4);label="measured",linewidth=2,color="yellow")
PyPlot.plot(dataindex(model4),meanevaldata;label="mean",linewidth=1,color="black")
PyPlot.xlim(dataindex(model4)[1],dataindex(model4)[end])
PyPlot.xlabel("Time (s)")
PyPlot.ylabel("Current (nA)")
PyPlot.legend(loc="upper right",fancybox="true")
PyPlot.title("Comparison of Mean vs Measured Light-Induced Current")
println("Evaluation paramater values: ")
display(paramvals)
println("Mean Log-Posterior for these parameters: ",mean(logposteriorvals))
In [ ]:
In [ ]: